package com.jfinal.ssl.controller;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.kit.Ret;
import com.jfinal.ssl.common.CaffeineKit;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.cert.CertificateException;

@Path("/ssl")
public class SslController extends Controller {
    @Inject
    SslServer sslServer;
    @Inject
    TencentServer tencentServer;

    //这个主要用来调试方法，正式直接启动就可以了，可以忽略这个文件
    public void doMain() throws IOException, CertificateException {
        renderJson(sslServer.doMain());
    }

    public void detailSSL(){
        renderJson(tencentServer.detailSSL("PKDCyt5S"));
    }

    public void getSslList() {
        if (tencentServer.getSslList() != null) {
            renderJson(Ret.ok().set("data", tencentServer.getSslList()));
        } else {
            renderJson(Ret.fail().set("msg", "未知异常"));
        }
    }

    public void getFreeSSL() {
        renderJson(tencentServer.getFreeSSL("jfinal.com"));
    }

    public void removeCache() {
        CaffeineKit.clearAll();
        renderJson(Ret.ok());
    }

    public void getCache(){
        renderJson(CaffeineKit.getKeys("cacheData"));
    }

    public void putCache(){
        //CaffeineKit.put("cacheData","test","test123");
        renderJson();
    }
}
